package com.jh.complicate.serializable;

import com.google.protobuf.InvalidProtocolBufferException;

import java.util.Arrays;

/**
 * @author Administrator
 * @projectName newforward
 * @title ProtobufTest.java
 * @package com.jh.complicate.serializable
 * @description Protobuf序列化测试
 * @date 2019/6/5 16:45
 */
public class ProtobufTest {
    public static void main(String[] args) throws InvalidProtocolBufferException {
        // 序列化
        UserProto.User user = UserProto.User.newBuilder().setName("JH").setAge(300).build();
        byte[] bytes = user.toByteArray();

        System.out.println("byte length：" + bytes.length);
        for (int i = 0; i < bytes.length; i++) {
            System.out.print(bytes[i] + " ");
        }
        System.out.println();

        UserProto.User tmp = UserProto.User.parseFrom(bytes);
        System.out.println(tmp);
    }
}
